﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace DataAccessAPI_2010_4
{
    class Program
    {
        /// <summary>
        /// MySQL Test
        /// </summary>
        /// <param name="args"></param>
        //static void Main(string[] args)
        //{
        //    DataSet_To_MySQL.DataAccess dataAccess;
        //    DataSet_To_MySQL.QueryStringBuilder queryStringBuilder = new DataSet_To_MySQL.QueryStringBuilder();
        //    dataAccess = new DataSet_To_MySQL.DataAccess();
        //    DataSet_To_MySQL.DataAccess.connectionString = queryStringBuilder.ConnectionStringBuild("dbfortest", "192.168.235.182", "root", "a121385743", false, "gb2312", "3306");
        //    dataAccess.ConnectionBuild();
        //    DataSet resultDataSet = new DataSet();
        //    resultDataSet = dataAccess.SelectQuery("select * from student;");
        //    if (resultDataSet == null)
        //    {
        //        Console.WriteLine("Nothing Selected!");
        //    }
        //    else if (resultDataSet != null)
        //    {
        //        Console.WriteLine(resultDataSet.Tables[0].Rows.Count);
        //    }
        //    string closeCommand = Console.ReadLine();
        //    if (closeCommand == "Close")
        //    {
        //        dataAccess.ConnectionClose();
        //    }
        //}
        /// <summary>
        /// XML Test
        /// </summary>
        /// <param name="args"></param>
        //static void Main(string[] args)
        //{
        //    string filePath;
        //    filePath = @"..\..\..\DataBases\XML\";
        //    LINQ_To_XML.XMLFileOperation newXMLFileOperation = new LINQ_To_XML.XMLFileOperation();
        //    newXMLFileOperation.FileCerate("test.xml", filePath);
        //}
        /// <summary>
        /// SQL Test
        /// </summary>
        /// <param name="args"></param>
        //static void Main(string[] args)
        //{

        //}
        /// <summary>
        /// 测试查询字符串生成函数
        /// </summary>
        /// <param name="args"></param>
        //static void Main(string[] args)
        //{
        //    string selectString;
        //    DataSet_To_MySQL.QueryStringBuilder selectStringBuilder = new DataSet_To_MySQL.QueryStringBuilder();
        //    List<string> tableName = new List<string>();
        //    List<string> columnName = new List<string>();
        //    List<string> conditionColumnName = new List<string>();
        //    List<string> conditionValue = new List<string>();
        //    List<string> conditionValueType = new List<string>();
        //    tableName.Add("TestTable");
        //    columnName.Add("TestColumn");
        //    conditionColumnName.Add("TestCondition1");
        //    conditionColumnName.Add("TestCondition2");
        //    conditionColumnName.Add("TestCondition3");
        //    conditionValue.Add("TestValue1");
        //    conditionValue.Add("TestValue2");
        //    conditionValue.Add("TestValue3");
        //    conditionValueType.Add("1");
        //    conditionValueType.Add("0");
        //    conditionValueType.Add("1");
        //    selectString = selectStringBuilder.SelectQueryStringBuilder(tableName, columnName, conditionColumnName, conditionValue, conditionValueType).ToString();
        //    Console.WriteLine(selectString);
        //    Console.ReadLine();
        //}
        /// <summary>
        /// Insert Query Test
        /// </summary>
        /// <param name="args"></param>
        //static void Main(string[] args)
        //{
        //    DataSet_To_MySQL.DataAccess dataAccess;
        //    DataSet_To_MySQL.QueryStringBuilder queryStringBuilder = new DataSet_To_MySQL.QueryStringBuilder();
        //    dataAccess = new DataSet_To_MySQL.DataAccess();
        //    DataSet_To_MySQL.DataAccess.connectionString = queryStringBuilder.ConnectionStringBuild("dbfortest", "192.168.235.182", "root", "a121385743", false, "gb2312", "3306");
        //    dataAccess.ConnectionBuild();
        //    dataAccess.InsertQuery("insert into dbfortest.student values (8,'addasfw',1,11,'dasf');");
        //    DataSet resultDataSet = new DataSet();
        //    resultDataSet = dataAccess.SelectQuery("select * from student;");
        //    if (resultDataSet == null)
        //    {
        //        Console.WriteLine("Nothing Selected!");
        //    }
        //    else if (resultDataSet != null)
        //    {
        //        Console.WriteLine(resultDataSet.Tables[0].Rows.Count);
        //    }
        //    string closeCommand = Console.ReadLine();
        //    if (closeCommand == "Close")
        //    {
        //        dataAccess.ConnectionClose();
        //    }
        //}
        static void Main(string[] args)
        {
            DataSet_To_MySQL.DataAccess dataAccess;
            DataSet_To_MySQL.QueryStringBuilder queryStringBuilder = new DataSet_To_MySQL.QueryStringBuilder();
            dataAccess = new DataSet_To_MySQL.DataAccess();
            DataSet_To_MySQL.DataAccess.connectionString = queryStringBuilder.ConnectionStringBuild("dbfortest", "192.168.235.182", "root", "a121385743", false, "gb2312", "3306");
            dataAccess.ConnectionBuild();
            dataAccess.DeleteQuery("delete from  dbfortest.student where Sno=8");
            DataSet resultDataSet = new DataSet();
            resultDataSet = dataAccess.SelectQuery("select * from student;");
            if (resultDataSet == null)
            {
                Console.WriteLine("Nothing Selected!");
            }
            else if (resultDataSet != null)
            {
                Console.WriteLine(resultDataSet.Tables[0].Rows.Count);
            }
            string closeCommand = Console.ReadLine();
            if (closeCommand == "Close")
            {
                dataAccess.ConnectionClose();
            }
        }
    }
}
